package com.mercycrazy.recruit.rabbit;

import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import static com.mercycrazy.recruit.constant.RabbitMQConstant.SMS_QUEUE_DEAD;

/**
 * Rabbit 短信发送相关死信队列的消费
 *
 * @author <a href="mailto:1443424326@qq.com">mercycrazy</a>
 * @since 2023-01-19
 */
@Component
@Slf4j
public class RabbitMQSMSDeadConsumer {

    @RabbitListener(queues = {SMS_QUEUE_DEAD})
    public void watchQueue(String payload, Channel channel, Message message) throws Exception {

        log.info("message enter in dead queue, routing key: [{}], payload: [{}]",
                message.getMessageProperties().getReceivedRoutingKey(),
                payload);

        channel.basicAck(message.getMessageProperties().getDeliveryTag(), true);
    }
}
